package com.teaching.teachingsupport.common.utils;

import com.teaching.teachingsupport.common.pojo.dto.response.AmountRequest;
import com.teaching.teachingsupport.common.pojo.dto.request.CreateUserRequest;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import com.teaching.teachingsupport.common.pojo.dataobject.User;
import java.time.LocalDateTime;

/**
 * Bean转换工具类
 */
public class BeanCover {
    
    /**
     * 统一设置数量属性
     * @param totalUsers 总用户数
     * @param teacherCount 教师数量
     * @param studentCount 学生数量
     * @param activeUsers 活跃用户数
     * @return AmountRequest对象
     */
    public static AmountRequest coverAmount(Integer totalUsers, Integer teacherCount, Integer studentCount, Integer activeUsers) {
        AmountRequest amountRequest = new AmountRequest();
        amountRequest.setTotalUsers(totalUsers);
        amountRequest.setTeacherCount(teacherCount);
        amountRequest.setStudentCount(studentCount);
        amountRequest.setActiveUsers(activeUsers);
        return amountRequest;
    }

    /**
     * 创建用户对象
     * @param request 创建用户请求
     * @param passwordEncoder 密码加密器
     * @return 用户对象
     */
    public static User coverUser(CreateUserRequest request, BCryptPasswordEncoder passwordEncoder) {
        User user = new User();
        user.setUsername(request.getUsername());
        user.setPasswordHash(passwordEncoder.encode(request.getPassword()));
        user.setRoleType(request.getRoleType());
        user.setStatus(0); // 正常状态
        user.setCreateTime(LocalDateTime.now());
        return user;
    }
} 